package com.jason.kotlin.gank.ui

import android.widget.EditText
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.jason.kotlin.gank.R
import com.jason.kotlin.gank.model.GankDataBean
import com.jason.kotlin.gank.ui.adapter.GankItemAdapter
import com.jason.kotlin.gank.viewmodel.GankSearchViewModel
import com.jason.library.common.base.BasePageStateActivity
import com.jason.library.common.base.loadmore.CustomLoadMoreView
import com.jason.library.common.ext.afterTextChange

/**
 * @description: GankSearchActivity
 *
 * @author ChenBaoyang
 * @date 4/20/21 16:39
 */
class GankSearchActivity : BasePageStateActivity<GankSearchViewModel, GankDataBean>() {

    private lateinit var keywordEdit: EditText
    private lateinit var searchTv: TextView

    override fun initView() {
        super.initView()
        keywordEdit = findViewById(R.id.edit_keyword)
        searchTv = findViewById(R.id.tv_search)

        searchTv.isEnabled = false
        keywordEdit.afterTextChange{
            searchTv.isEnabled = !it.isNullOrBlank()
        }
        searchTv.setOnClickListener {
            viewModel!!.keyword = keywordEdit.text.toString()
            viewModel!!.loadData()
        }
        super.initView()
    }


    override fun getAdapter(): BaseQuickAdapter<GankDataBean, BaseViewHolder> = GankItemAdapter()


    override fun getLayoutId() = R.layout.gank_activity_search

}